//
//  WYWRefreshGifHeader.m
//  15WClient
//
//  Created by JinYong on 16/5/9.
//  Copyright © 2016年 15w. All rights reserved.
//

#import "WYWRefreshGifHeader.h"

static const NSTimeInterval kHeaderTimeInterval = 1.f;

@implementation WYWRefreshGifHeader

#pragma mark - 重写方法
#pragma mark 基本设置
- (void)prepare
{
    [super prepare];
    self.backgroundColor = [UIColor clearColor];
    // 设置普通状态的动画图片
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<=1; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"h_loading_%0.2ld", (unsigned long)i]];
        [idleImages addObject:image];
    }
    [self setImages:idleImages duration:kHeaderTimeInterval forState:MJRefreshStateIdle];
    
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<=61; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"h_loading_%0.2ld", (unsigned long)i]];
        [refreshingImages addObject:image];
    }
    [self setImages:refreshingImages duration:kHeaderTimeInterval forState:MJRefreshStatePulling];
    
    // 设置正在刷新状态的动画图片
    [self setImages:refreshingImages duration:kHeaderTimeInterval forState:MJRefreshStateRefreshing];
}

- (void)placeSubviews
{
    [super placeSubviews];
    
    [self.superview bringSubviewToFront:self];
    
    for (UIView *v in self.subviews) {
        if ([v isKindOfClass:[UIImageView class]]) {
            v.contentMode = UIViewContentModeBottom;
//            v.y = self.isMain?15.f:-10.f;
        }
    }
}

@end
